<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script type="text/javascript" src="/webjars/jquery/3.4.1/jquery.js"></script>
    <script type="text/javascript" src="/webjars/bootstrap/3.3.7/js/bootstrap.js"></script>
    <script type="text/javascript" src="/webjars/vue/2.6.10/dist/vue.js"></script>
    <script type="text/javascript" src="/webjars/axios/0.19.0/dist/axios.js"></script>
    <link type="text/css" rel="stylesheet" href="/webjars/bootstrap/3.3.7/css/bootstrap.css">
</head>
<body>
<div id="vuebox">
    <div class="container" style="margin-top: 50px">
        <div class="row">
            <div class="col-md-6">
                <form class="form-inline" role="form" style="padding-left: 250px;">
                    <div class="form-group" style="padding-left: 20px;">
                        查询联系人:
                        <input type="text" id="department"/>
                        <button type="button"  @click="selectPerson()">查找</button>
                    </div>

                </form>
            </div>
            <div class="col-md-4 text-right">
                <a href="#" class="btn btn-primary" @click.stop="showModal()">新增</a>
            </div>
        </div>
        <br/>
        <table class="table table-striped">
            <thead>
            <tr>
                <th>编号</th>
                <th>数量</th>
                <th>出库时间</th>
                <th>经手人</th>
                <th>操作</th>
            </tr>
            </thead>
            <tbody>
            <!--private String name;

            private Integer gender;

            private Integer age;

            private Integer rank;

            private String department;-->
            <tr v-for="item in persons.data.list">
                <td>{{item.id}}</td>
                <td>{{item.name}}</td>
                <td>{{item.gender}}</td>
                <td>{{item.age}}</td>
                <td>{{item.rank}}</td>
                <td>{{item.department}}</td>

                <td>
                    <button class="btn btn-success" @click="to_update(item.id)">修改</button>
                    <button class="btn btn-danger"@click="del(item.id)">删除</button>
                </td>
            </tr>
            </tbody>
        </table>
        <br/>
        <div class="text-center">
            <ul class="pagination">
                <li :class="{disabled:!persons.data.hasPreviousPage}">
                    <a href="#" @click.stop="selectPerson(persons.data.perPage)">&laquo;</a>
                </li>
                <li :class="{active:persons.data.pageNum==i}" v-for="i in persons.data.navigatepageNums">
                    <a href="#" @click.stop="selectPerson(i)">{{i}}</a>
                </li>
                <li :class="{disabled:!persons.data.hasNextPage}">
                    <a href="#" @click.stop="selectPerson(persons.data.nextPage)">&raquo;</a>
                </li>
            </ul>
        </div>
    </div>
    <!--模态框-->
    <div class="modal" id="mymodal">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <button class="close" type="button" @click="hideModal()">&times;</button>
                    <div class="modal-title">
                    </div>
                </div>
                <div class="modal-body">
                    <form class="form-horizontal" role="form">
                        <div class="form-group">
                            <label for="id" class="col-sm-2 control-label">编号</label>
                            <div class="col-sm-10">
                                <input v-model="new_long.id" id="id" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="name" class="col-sm-2 control-label">姓名</label>
                            <div class="col-sm-10">
                                <input v-model="new_person.name" id="name" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="gender" class="col-sm-2 control-label">性别</label>
                            <div class="col-sm-10">
                                <select id="gender" class="form-control" v-model="new_person.gender">
                                    <option value="0">全部</option>
                                    <option v-for="item in persons.data" :value="item.id">{{item.productname}}</option>
                                </select>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="quantity" class="col-sm-2 control-label">数量</label>
                            <div class="col-sm-10">
                                <input v-model="new_long.quantity" id="quantity" type="text" class="form-control">
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="handler" class="col-sm-2 control-label">经手人</label>
                            <div class="col-sm-10">
                                <input v-model="new_long.handler" id="handler" type="text" class="form-control"/>
                            </div>
                        </div>
                        <div class="form-group">
                            <label for="outdate" class="col-sm-2 control-label">时间</label>
                            <div class="col-sm-10">
                                <input v-model="new_long.outdate" id="outdate" type="text" class="form-control">
                            </div>
                        </div>
                    </form>
                </div>
                <div class="modal-footer">
                    <button class="btn btn-default" @click="hideModal()">关闭</button>
                    <button class="btn btn-primary" @click="save()">保存</button>
                </div>
            </div>
        </div>
    </div>
</div>
</body>
</html>
<script type="text/javascript">
    var vm=new Vue({
        el:"#vuebox",
        data:{
            persons:{},
            pageNum:'',
            delResult:{},
            department:null,
            new_person:{id:'', name:'',gender:'',age:'',rank:'',department:''}

        },
        methods:{
            selectPerson:function (pageNum) {
                axios.get("http://localhost:8080/selAll",{params:{pageNum:this.pageNum,department:this.department}}).then(res=>{
                    this.persons=res.data;
                    this.pageNum=pageNum;
                })
            } ,del:function (id) {
                axios.get("http://localhost:8080/delById",{params:{id:id}}).then(res=>{
                    this.delResult=res.data;
                    if (this.delResult.result=='SUCCESS'){
                        alert("删除成功")
                        this.selectPerson(this.pageNum);
                    }else {
                        alert(this.delResult.message);
                    }
                });
            },
            showModal:function () {
                $('#mymodal').modal('show');
            },
            hideModal:function () {
                $('#mymodal').modal('hide');
                this.clearForm();
            },
            clearForm:function () {
                $('#id').val();
                $('#name').val('');
                $('#gender').val('');
                $('#age').val('');
                $('#rank').val('');
                $('#department').val('');

            },
            save:function () {
                axios.post("http://localhost:8080/save",this.new_person).then(res=>{
                    this.delResult=res.data.data;
                    if (this.delResult.result=='SUCCESS'){
                        this.selectPerson(this.pageNum);

                        this.hideModal();

                    }else {
                        alert(this.delResult.message);
                    }
                })
            },
            to_update:function(id){
                axios.get("http://localhost:8080/getById",{params:{id:id}}).then(res=>{
                    this.new_person=res.data.data;
                    this.showModal();
                })
            }

        },mounted(){
            this.selectPerson(1)
        }
    })
</script>